package dao;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.ejb.Stateless;

import model.Passenger;

@Stateless
public class PassengerDAO extends GenericDAO<Passenger> {
	
	public PassengerDAO() {
		super(Passenger.class);  
	}
	  
	public Passenger findPassengerByLogin(String login) {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("login", login);
		List<Passenger> passenger = super.findManyResults(Passenger.FIND_BY_LOGIN, parameters);
		if (passenger != null) {
			if (passenger.isEmpty()) {
				return null;
			} else {
				return passenger.get(0);
			}
		} else {
			return null;
		}
	}
	
	public Passenger findByNameSurname(String name, String surname) {
		Map<String, Object> parameters = new HashMap<String, Object>();
		parameters.put("name", name);
		parameters.put("surname", surname);
		List<Passenger> passenger = super.findManyResults(Passenger.FIND_BY_NAME_SURNAME, parameters);
		if (passenger != null) {
			if (passenger.isEmpty()) {
				return null;
			} else {
				return passenger.get(0);
			}
		} else {
			return null;
		}
	}
}
